<?php
/**
 * Created by PhpStorm.
 * User: Celebration-Grey
 * Date: 2017/5/20
 * Time: 19:31
 */

namespace App\Http\Classes;


use Illuminate\Support\Facades\DB;

class Friend
{
    public static function friendAdd($data){
        if(isset($data['master_user_id']) && isset($data['friend_user_id']) && isset($data['friend_group_id'])){
            $friend = DB::table('weibo_friends');
            $dataArray = array();
            $dataArray['master_user_id'] = $data['master_user_id'];
            $dataArray['friend_user_id'] = $data['friend_user_id'];
            $dataArray['friend_group_id'] = $data['friend_group_id'];
            if(isset($data['friend_remark'])){
                $dataArray['friend_remark'] = $data['friend_remark'];
            }
            $friend = $friend -> insertGetId($dataArray);
            if($friend){
                return true;
            }
            else{
                return null;
            }
        }
        else{
            return false;
        }
    }

    public static function isFriend($data){
        if(isset($data['master_user_id']) && isset($data['friend_user_id'])){
            $friend = DB::table('weibo_friends');
            $result = $friend -> where('master_user_id','=',$data['master_user_id']) -> where('friend_user_id','=',$data['friend_user_id']) -> count();
            if($result >= 1){
                return true;
            }
            else{
                return false;
            }
        }
        else{
            return null;
        }
    }
}